package com.cuijq.eduservice.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Classname MyBatisPlusConfig
 * @Description TODO
 * @Date 2021/3/25 10:05
 * @Created by CuiJQ
 */
@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = "com.cuijq.eduservice.mapper")
public class MyBatisPlusConfig {


  /**
   * sql 执行性能分析插件
   * @return
   */
  @Bean
  @Profile({"dev","test"})
  public PerformanceInterceptor performanceInterceptor(){
    PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
    performanceInterceptor.setMaxTime(1000);//ms
    performanceInterceptor.setFormat(true);
    return performanceInterceptor;
  }

  /**
   * 逻辑删除插件
   * @return
   */
  @Bean
  public ISqlInjector sqlInjector(){
    return new LogicSqlInjector();
  }

  /**
   * 分页插件
   * @return
   */
  @Bean
  public PaginationInterceptor paginationInterceptor(){
    return new PaginationInterceptor();
  }
}
